﻿using System;

namespace NeuralLib.ActivationFunction
{
    public class HyperbolicTangentFunction:IActivationFunction
    {
        public HyperbolicTangentFunction(double alpha)
        {
            _alpha = alpha;
        }

        public HyperbolicTangentFunction()
            : this(1) { }

        private readonly double _alpha;
        public double Alpha
        {
            get
            {
                return _alpha;
            }
        }

        public double Derivative(double x)
        {
           var y = Function(x);
            return (1 - y * y);
        }

        public double Derivative2(double y) { return (1 - y * y); }

        public double Function(double x)
        {
            return ( (Math.Exp(x / _alpha) - Math.Exp(-x / _alpha)) / (Math.Exp(x / _alpha) + Math.Exp(-x / _alpha)) );
        }
    }
}
